﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace ShenLanCMS.Models
{
    /// <summary>
    /// 评论实体
    /// </summary>
    public class Comment
    {
        [Key]
        public Guid CommentID { get; set; }

        /// <summary>
        /// 文章id
        /// </summary>
        [Display(Name = "文章id")]
        public Guid PostID { get; set; }

        ///// <summary>
        ///// 标题
        ///// </summary>
        //[Display(Name="标题")]
        //public string Title { get; set; }

        /// <summary>
        /// 评论内容
        /// </summary>
        [Display(Name = "评论内容")]
        [Required(ErrorMessage = "请填写{0}")]
        [DataType(DataType.MultilineText)]
        [StringLength(1024, ErrorMessage = "不能超过{1}个字符.")]
        public string Content { get; set; }

        /// <summary>
        /// 评论者
        /// </summary>
        [Display(Name = "评论者")]
        [StringLength(36)]
        public Guid? UserID { get; set; }

        /// <summary>
        /// 昵称
        /// </summary>
        [Display(Name = "昵称")]
        [StringLength(20)]
        public string NickName { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        [Display(Name = "邮箱")]
        [StringLength(32)]
        public string Email { get; set; }

        /// <summary>
        /// 个人主页
        /// </summary>
        [Display(Name = "个人主页")]
        public string SiteUrl { get; set; }

        /// <summary>
        /// 评论时间
        /// </summary>
        [Display(Name = "评论时间")]
        public DateTime CommentTime { get; set; }

        /// <summary>
        /// 获取评论的文章信息
        /// </summary>
        /// <returns></returns>
        public Post GetPost()
        {
            var db = new EntityContext();
            var post = db.Posts.SingleOrDefault(n => n.PostID == this.PostID);
            if (post == null)
                post = new Post();
            return post;
        }
    }
}
